Package-level declarations

Core resilience patterns: Bulkhead, Cache, CircuitBreaker (consecutive-failure and SlidingWindowCircuitBreaker failure-rate variants), RateLimiter, RetryRepeat (plus RetryBudget against retry storms), Saga, TimeLimiter, AdaptiveLimiter, Hedge, Failover (with active health-probing), and Chaos (fault-injection test helpers). Each with DSL builders and named registries. Policy composes patterns into reusable chains; FlowResilience provides Flow-native counterparts. SharedStateStore is an extension point for distributing state across instances. MicrometerBridge (JVM-only, optional) exports statistics as Micrometer gauges.

Types

Link copied to clipboard

AIMD-based adaptive concurrency limiter. See file-level docs for details.

Link copied to clipboard
data class AdaptiveLimiterConfig(val initialLimit: Int = 20, val minLimit: Int = 1, val maxLimit: Int = 200, val increaseStep: Int = 1, val decreaseFactor: Double = 0.5, val latencyThreshold: Duration? = null)

Configuration for AdaptiveLimiter.

Link copied to clipboard

Registry for managing multiple named adaptive limiters.

Link copied to clipboard
@Serializable
data class AdaptiveLimiterStatistics(val currentLimit: Int, val inFlight: Int, val totalCalls: Long, val overloadEvents: Long)

Snapshot of AdaptiveLimiter state.

Link copied to clipboard
data class AttemptResult<R>(val attemptNumber: Int, val result: Result<R>, val duration: Duration)

Result of a single attempt in a retry operation.

Link copied to clipboard
class Bulkhead

Bulkhead pattern implementation for concurrency isolation.

Link copied to clipboard
data class BulkheadConfig(val maxConcurrentCalls: Int = 10, val maxWaitingCalls: Int = 10, val maxWaitDuration: Duration? = null)

Configuration for bulkhead behavior.

Link copied to clipboard

Builder for bulkhead configuration.

Link copied to clipboard
class BulkheadFullException(message: String, cause: Throwable? = null) : Exception

Exception thrown when the bulkhead is full.

Link copied to clipboard

Listener interface for bulkhead events.

Link copied to clipboard

Registry for managing named bulkhead instances.

Link copied to clipboard
@Serializable
data class BulkheadSettings(val maxConcurrentCalls: Int = BulkheadConfig().maxConcurrentCalls, val maxWaitingCalls: Int = BulkheadConfig().maxWaitingCalls, val maxWaitDuration: Duration? = null)

Serializable mirror of BulkheadConfig.

Link copied to clipboard
@Serializable
data class BulkheadStatistics(val totalCalls: Long, val successfulCalls: Long, val failedCalls: Long, val rejectedCalls: Long, val availableCapacity: Int, val utilizationRate: Double)

Statistics tracked by a bulkhead.

Link copied to clipboard
class BulkheadTimeoutException(message: String, cause: Throwable? = null) : Exception

Exception thrown when waiting for a bulkhead permit times out.

Link copied to clipboard
class Cache<K, V>

Thread-safe cache with TTL, eviction strategies, and statistics.

Link copied to clipboard
data class CacheConfig(val maxSize: Int = 100, val ttl: Duration? = 5.minutes, val evictionStrategy: EvictionStrategy = EvictionStrategy.LRU)

Configuration for cache behavior.

Link copied to clipboard

Builder for cache configuration.

Link copied to clipboard
interface CacheListener<K, V>

Listener for cache events.

Link copied to clipboard

Registry for managing named cache instances.

Link copied to clipboard
@Serializable
data class CacheStatistics(val hits: Long, val misses: Long, val evictions: Long, val size: Int, val hitRate: Double, val missRate: Double = 0.0, val utilizationRate: Double = 0.0, val currentSize: Int = size)

Statistics tracked by a cache.

Link copied to clipboard
data class ChaosConfig(val failureRate: Double = 0.0, val latency: Duration = Duration.ZERO, val latencyJitter: Duration = Duration.ZERO, val random: Random = Random.Default, val exception: () -> Throwable = { ChaosException() })

Configuration for chaos-injected faults.

Link copied to clipboard
Link copied to clipboard
class ChaosException(message: String = "Simulated failure injected by chaos()") : Exception

Thrown by chaos-wrapped operations when a simulated failure is injected.

Link copied to clipboard

Circuit breaker pattern to prevent cascading failures.

Link copied to clipboard
data class CircuitBreakerConfig(val failureThreshold: Int = 5, val resetTimeout: Duration = 30.seconds, val halfOpenSuccessThreshold: Int = 2, val halfOpenMaxCalls: Int = 3)

Configuration for circuit breaker behavior.

Link copied to clipboard

Builder for circuit breaker configuration.

Link copied to clipboard

Listener for circuit breaker state changes.

Link copied to clipboard
class CircuitBreakerOpenException(message: String, cause: Throwable? = null) : Exception

Exception thrown when circuit breaker is open.

Link copied to clipboard

Registry for managing multiple named circuit breakers.

Link copied to clipboard
@Serializable
data class CircuitBreakerSettings(val failureThreshold: Int = CircuitBreakerConfig().failureThreshold, val resetTimeout: Duration = CircuitBreakerConfig().resetTimeout, val halfOpenSuccessThreshold: Int = CircuitBreakerConfig().halfOpenSuccessThreshold, val halfOpenMaxCalls: Int = CircuitBreakerConfig().halfOpenMaxCalls)

Serializable mirror of CircuitBreakerConfig.

Link copied to clipboard

Circuit breaker state.

Link copied to clipboard
@Serializable
data class CircuitBreakerStats(val state: CircuitBreakerState, val failures: Int, val successes: Int)

Statistics for a circuit breaker.

Link copied to clipboard
data class CompensationError(val stepName: String, val stepIndex: Int, val error: Exception)

Information about a compensation error.

Link copied to clipboard

Isolation-by-dispatcher bulkhead: like Bulkhead, but every admitted call runs on a dedicated CoroutineDispatcher instead of the caller's context.

Link copied to clipboard
class DistributedCircuitBreaker(store: SharedStateStore, key: String, config: CircuitBreakerConfig = CircuitBreakerConfig(), clock: Clock = Clock.System)

Cross-instance circuit breaker whose state lives in a SharedStateStore: when one instance trips the breaker, every instance sharing the store fails fast. Semantics follow CircuitBreaker (Closed → Open → HalfOpen), with CircuitBreakerConfig.halfOpenMaxCalls not enforced across processes.

Link copied to clipboard
class DistributedRateLimiter(store: SharedStateStore, key: String, maxRequests: Int, window: Duration, clock: Clock = Clock.System)

Cross-instance fixed-window rate limiter whose counter lives in a SharedStateStore (e.g. a Redis-backed one), so every process sharing the store shares one budget of maxRequests per window.

Link copied to clipboard
object DurationMillisSerializer : KSerializer<Duration>

Serializes Duration as whole milliseconds (a Long) for TimeLimiterStatistics. kotlin.time.Duration has no built-in @Serializable support at the kotlinx-serialization version this module targets, so statistics that carry a duration use this explicit serializer instead.

Link copied to clipboard

Reason an entry was evicted from the cache.

Link copied to clipboard

Strategy used to determine which cache entries to evict.

Link copied to clipboard
class Failover<T>

Failover pattern: try a prioritized list of named providers, falling through to the next one when the current provider's circuit is open or it fails outright.

Link copied to clipboard
data class FailoverAttempt(val provider: String, val reason: FailoverAttempt.Reason, val cause: Throwable?)

A single attempt recorded during Failover.execute: either a provider was skipped because its circuit was open, or it was invoked and failed.

Link copied to clipboard

Builder for Failover, used via the failover DSL function.

Link copied to clipboard

Thrown by Failover.execute when every configured provider was either skipped (circuit open) or invoked and failed.

Link copied to clipboard
data class FailoverProviderStatistics(val name: String, val state: CircuitBreakerState, val successes: Long, val failures: Long, val skipped: Long)

Invocation statistics for a single provider within a Failover, as of Failover.statistics.

Link copied to clipboard

Registry for managing multiple named Failover chains.

Link copied to clipboard
data class HedgeConfig(val hedgeDelay: Duration = 100.milliseconds, val maxHedges: Int = 1)

Configuration for the hedged-request pattern.

Link copied to clipboard

Single-process, STM-backed SharedStateStore implementation. Useful for tests and as a reference implementation — it does not coordinate across processes/machines.

Link copied to clipboard
class LoadingCache<K, V>

A cache that automatically loads values on cache miss.

Link copied to clipboard

Binds resilience-pattern statistics to a Micrometer MeterRegistry as gauges.

Link copied to clipboard

Parallel saga coordinator for executing multiple sagas concurrently.

Link copied to clipboard
data class ParallelSagaResult<T>(val results: List<SagaResult<T>>, val totalSagas: Int, val successfulSagas: Int, val failedSagas: Int, val duration: Duration)

Result of parallel saga execution.

Link copied to clipboard
interface Policy

A composable resilience decorator: applies some cross-cutting behavior (retry, circuit breaking, rate limiting, ...) around a suspend operation.

Link copied to clipboard

Token bucket rate limiter for controlling request throughput.

Link copied to clipboard
data class RateLimiterConfig(val permitsPerSecond: Double = 10.0, val burstCapacity: Int = 10)

Configuration for rate limiter behavior.

Link copied to clipboard

Builder for rate limiter configuration.

Link copied to clipboard

Listener for rate limiter events.

Link copied to clipboard

Registry for managing multiple named rate limiters.

Link copied to clipboard
@Serializable
data class RateLimiterSettings(val permitsPerSecond: Double = RateLimiterConfig().permitsPerSecond, val burstCapacity: Int = RateLimiterConfig().burstCapacity)

Serializable mirror of RateLimiterConfig.

Link copied to clipboard
@Serializable
data class RateLimiterStatistics(val availableTokens: Double, val totalRequests: Long, val acceptedRequests: Long, val rejectedRequests: Long)

Statistics for a rate limiter.

Link copied to clipboard
class RateLimitExceededException(message: String, cause: Throwable? = null) : Exception

Exception thrown when rate limit is exceeded.

Link copied to clipboard
@Serializable
data class ResilienceConfig(val circuitBreakers: Map<String, CircuitBreakerSettings> = emptyMap(), val bulkheads: Map<String, BulkheadSettings> = emptyMap(), val rateLimiters: Map<String, RateLimiterSettings> = emptyMap(), val timeLimiters: Map<String, TimeLimiterSettings> = emptyMap())

Declarative, externalizable configuration for named resilience instances (the application.yml-style equivalent of the programmatic DSLs).

Link copied to clipboard

Live, named resilience instances built from a ResilienceConfig.

Link copied to clipboard

Retry budget: a system-wide guard against retry storms.

Link copied to clipboard
data class RetryBudgetConfig(val maxTokens: Double = 10.0, val tokenRatio: Double = 0.1)

Configuration for a RetryBudget.

Link copied to clipboard

Thrown by retryWithBudget when a retry would be warranted (the operation failed and attempts remain) but budget has no tokens left -- failing fast instead of piling onto a downstream that retries elsewhere in the system may already be overwhelming.

Link copied to clipboard
data class RetryResult<R>(val finalResult: Result<R>, val attempts: List<AttemptResult<R>>, val totalDuration: Duration)

Result of a retry operation with history.

Link copied to clipboard
class Saga<T>

Saga pattern for distributed transactions with compensation.

Link copied to clipboard
class SagaBuilder<T>(clock: Clock = Clock.System)

Builder for constructing a saga with multiple steps.

Link copied to clipboard
data class SagaConfig(val continueOnCompensationFailure: Boolean = true, val compensationTimeout: Duration? = null)

Configuration for saga execution behavior.

Link copied to clipboard

Registry for managing multiple named, reusable saga templates.

Link copied to clipboard
sealed class SagaResult<T>

Result of saga execution.

Link copied to clipboard
data class SagaStep<R, T>(val name: String, val action: suspend () -> R, val compensation: suspend (R) -> Unit? = null)

Represents a single step in a saga.

Link copied to clipboard
class SagaStepException(val stepName: String, cause: Throwable) : Exception

Exception thrown when a saga step fails.

Link copied to clipboard

A minimal shared, string-keyed key-value store for cross-instance coordination of resilience state. See file-level docs for intended usage.

Link copied to clipboard

Sliding-window circuit breaker: trips on a failure rate over the last N calls, rather than CircuitBreaker's consecutive-failure count.

Link copied to clipboard
data class SlidingWindowCircuitBreakerConfig(val slidingWindowSize: Int = 100, val minimumNumberOfCalls: Int = 10, val failureRateThreshold: Double = 0.5, val resetTimeout: Duration = 30.seconds, val halfOpenSuccessThreshold: Int = 2)

Configuration for SlidingWindowCircuitBreaker.

Link copied to clipboard

Registry for managing multiple named sliding-window circuit breakers.

Link copied to clipboard
@Serializable
data class SlidingWindowCircuitBreakerStatistics(val state: CircuitBreakerState, val callsInWindow: Int, val failuresInWindow: Int, val failureRate: Double)

Statistics for a SlidingWindowCircuitBreaker.

Link copied to clipboard
data class SlidingWindowConfig(val maxRequests: Int = 100, val windowDuration: Duration = 60.seconds)

Configuration for sliding window rate limiter.

Link copied to clipboard

Sliding window rate limiter implementation.

Link copied to clipboard
@Serializable
data class SlidingWindowStatistics(val currentRequests: Int, val totalRequests: Long, val acceptedRequests: Long, val rejectedRequests: Long)

Statistics for a sliding window rate limiter.

Link copied to clipboard

Thread-pool-isolation bulkhead (JVM). Admitted calls run on a dedicated fixed-size thread pool of BulkheadConfig.maxConcurrentCalls threads, so slow or blocking calls can never consume threads outside the pool.

Link copied to clipboard

Time limiter for enforcing execution timeouts.

Link copied to clipboard
data class TimeLimiterConfig(val timeout: Duration = 30.seconds)

Configuration for time limiter behavior.

Link copied to clipboard

Builder for time limiter configuration.

Link copied to clipboard

Listener for time limiter events.

Link copied to clipboard

Registry for managing multiple named time limiters.

Link copied to clipboard
@Serializable
data class TimeLimiterSettings(val timeout: Duration = TimeLimiterConfig().timeout)

Serializable mirror of TimeLimiterConfig.

Link copied to clipboard
@Serializable
data class TimeLimiterStatistics(val totalCalls: Long, val successfulCalls: Long, val timedOutCalls: Long, val failedCalls: Long, val averageTimeoutDuration: Duration)

Statistics for a time limiter.

Functions

Link copied to clipboard

DSL for creating a configured AdaptiveLimiter.

Link copied to clipboard
suspend fun bulkhead(configure: BulkheadConfigBuilder.() -> Unit): Bulkhead

DSL for creating a configured Bulkhead instance.

Link copied to clipboard
suspend fun <K, V> cache(configure: CacheConfigBuilder.() -> Unit): Cache<K, V>

Creates a cache with DSL-style configuration.

Link copied to clipboard
fun <T> chaos(config: ChaosConfig = ChaosConfig(), block: suspend () -> T): suspend () -> T

Wraps block so that invoking the returned function injects latency and/or failures according to config.

fun <T> chaos(configure: ChaosConfigBuilder.() -> Unit, block: suspend () -> T): suspend () -> T

DSL variant of chaos using a config builder.

Link copied to clipboard

Creates a circuit breaker with DSL-style configuration.

Link copied to clipboard
suspend fun <T> executeSaga(clock: Clock = Clock.System, configure: SagaBuilder<T>.() -> Unit): SagaResult<T>

Executes a saga and returns the result.

Link copied to clipboard
suspend fun <T> failover(configure: suspend FailoverBuilder<T>.() -> Unit): Failover<T>

Creates a Failover with DSL-style configuration.

Link copied to clipboard
suspend fun <T> hedge(config: HedgeConfig, block: suspend () -> T): T

Executes block using the hedged-request pattern: the primary attempt starts immediately, and up to HedgeConfig.maxHedges additional attempts start at increasing multiples of HedgeConfig.hedgeDelay if the previous attempts haven't completed yet. The first attempt to succeed wins; the rest are cancelled. If every attempt fails, the last failure is rethrown.

suspend fun <T> hedge(hedgeDelay: Duration = 100.milliseconds, maxHedges: Int = 1, block: suspend () -> T): T

Executes block using the hedged-request pattern with named parameters instead of a HedgeConfig instance — convenient for one-off calls.

Link copied to clipboard
fun hedgePolicy(hedgeDelay: Duration = 100.milliseconds, maxHedges: Int = 1): Policy

A Policy that runs the hedged-request pattern (see hedge): block may be started more than once, concurrently, after hedgeDelay (and again every hedgeDelay up to maxHedges times) if the earlier attempt(s) haven't completed yet, resolving to whichever attempt succeeds first. block must be safe to run multiple times concurrently (e.g. an idempotent GET).

Link copied to clipboard
suspend fun rateLimiter(configure: RateLimiterConfigBuilder.() -> Unit): RateLimiter

Creates a rate limiter with DSL-style configuration.

Link copied to clipboard
suspend fun <R> repeatAndCollect(times: Long = 3, delay: Duration = 500.milliseconds, block: suspend () -> R): List<R>

Repeats an operation and collects all results.

Link copied to clipboard
suspend fun <R> repeatOrElse(times: Long = 3, delay: Duration = 500.milliseconds, onError: suspend (Throwable, Long) -> R, block: suspend () -> R): R

Repeats an operation and invokes an error handler if any execution fails.

Link copied to clipboard
suspend fun <R> repeatUntil(maxAttempts: Long = 10, delay: Duration = 500.milliseconds, condition: (R) -> Boolean, block: suspend () -> R): R

Repeats an operation until a condition is met or max attempts are reached.

Link copied to clipboard
suspend fun <R> repeatWhile(maxAttempts: Long = 10, delay: Duration = 500.milliseconds, predicate: (R) -> Boolean, block: suspend () -> R): List<R>

Repeats an operation while a condition is true, collecting all results.

Link copied to clipboard
suspend fun <R> repeatWithExponentialBackoff(times: Long = 3, base: Duration = 1.seconds, factor: Double = 2.0, block: suspend () -> R): R

Repeats a successful operation with exponential backoff delay between repetitions.

Link copied to clipboard
suspend fun <R> repeatWithFixedDelay(times: Long = 3, delay: Duration = 500.milliseconds, block: suspend () -> R): R

Repeats a successful operation with constant delay between repetitions.

Link copied to clipboard
suspend fun <R> repeatWithTimeout(timeout: Duration, times: Long = 3, delay: Duration = 500.milliseconds, block: suspend () -> R): R

Repeats an operation with a timeout for the entire repeat cycle.

Link copied to clipboard
suspend fun <R> retryIf(retries: Long = 3, delay: Duration = 1.seconds, shouldRetry: (Throwable) -> Boolean, block: suspend () -> R): R

Executes a suspend operation with retry using a custom predicate to decide retries.

Link copied to clipboard
fun retryIfPolicy(retries: Long = 3, base: Duration = 200.milliseconds, factor: Double = 2.0, shouldRetry: (Throwable) -> Boolean): Policy

A Policy that retries with exponential backoff and jitter like retryPolicy, but only for exceptions matching shouldRetry, backed by retryIfWithExponentialBackoff. Prefer this over retryPolicy whenever some failures are permanent (e.g. a 4xx response, a validation error) and shouldn't be retried at all.

Link copied to clipboard
suspend fun <R> retryIfWithCappedBackoff(retries: Long = 3, base: Duration = 200.milliseconds, maxDelay: Duration = 10.seconds, factor: Double = 2.0, shouldRetry: (Throwable) -> Boolean, block: suspend () -> R): R

Executes a suspend operation with retry using exponential backoff capped at a maximum delay, like retryWithCappedBackoff - but, unlike that, only for exceptions matching shouldRetry. Combines retryWithCappedBackoff's bounded backoff with retryIf's conditional retry.

Link copied to clipboard
suspend fun <R> retryIfWithExponentialBackoff(retries: Long = 3, base: Duration = 200.milliseconds, factor: Double = 2.0, shouldRetry: (Throwable) -> Boolean, block: suspend () -> R): R

Executes a suspend operation with retry using exponential backoff and jitter, but only for exceptions matching shouldRetry - combines retryWithExponentialBackoff's backoff strategy with retryIf's conditional retry, which neither function offers alone.

Link copied to clipboard
suspend fun <R> retryOrDefault(retries: Long = 3, base: Duration = 200.milliseconds, factor: Double = 2.0, fallback: suspend (Throwable) -> R, block: suspend () -> R): R

Executes a suspend operation with retry and returns a fallback value if all retries fail.

Link copied to clipboard
fun retryPolicy(retries: Long = 3, base: Duration = 200.milliseconds, factor: Double = 2.0): Policy

A Policy that retries with exponential backoff and jitter, backed by retryWithExponentialBackoff.

Link copied to clipboard
suspend fun <T> retryWithBudget(budget: RetryBudget, retries: Long = 3, initialDelay: Duration = 100.milliseconds, maxDelay: Duration = 1.minutes, factor: Double = 2.0, block: suspend () -> T): T

Like retryWithExponentialBackoff, but every retry (not the initial attempt) must first withdraw a token from budget -- see RetryBudget for why this matters. A successful call (whether on the first attempt or a later one) deposits a token back into the budget.

Link copied to clipboard
suspend fun <R> retryWithCappedBackoff(retries: Long = 3, base: Duration = 200.milliseconds, maxDelay: Duration = 10.seconds, factor: Double = 2.0, block: suspend () -> R): R

Executes a suspend operation with retry using exponential backoff capped at a maximum delay.

Link copied to clipboard
suspend fun <R> retryWithConstantDelay(retries: Long = 3, delay: Duration = 1.seconds, block: suspend () -> R): R

Executes a suspend operation with retry using constant delay between attempts.

Link copied to clipboard
suspend fun <R> retryWithExponentialBackoff(retries: Long = 3, base: Duration = 200.milliseconds, factor: Double = 2.0, block: suspend () -> R): R

Executes a suspend operation with retry capabilities using exponential backoff and jitter.

Link copied to clipboard
suspend fun <R> retryWithFibonacci(retries: Long = 5, base: Duration = 100.milliseconds, block: suspend () -> R): R

Executes a suspend operation with retry using Fibonacci sequence for delays.

Link copied to clipboard
suspend fun <R> retryWithHistory(retries: Long = 3, base: Duration = 200.milliseconds, factor: Double = 2.0, clock: Clock = Clock.System, block: suspend () -> R): RetryResult<R>

Executes a suspend operation with retry and collects detailed history of all attempts.

Link copied to clipboard
fun <T> saga(clock: Clock = Clock.System, configure: SagaBuilder<T>.() -> Unit): Saga<T>

DSL function for creating a saga.

Link copied to clipboard

Creates a sliding-window circuit breaker with DSL-style configuration.

Link copied to clipboard
suspend fun timeLimiter(configure: TimeLimiterConfigBuilder.() -> Unit): TimeLimiter

Creates a time limiter with DSL-style configuration.

Link copied to clipboard
suspend fun <T> tryWithBulkhead(config: BulkheadConfig = BulkheadConfig(), block: suspend () -> T): T?

Tries to execute an operation with bulkhead protection, returning null if rejected.

Link copied to clipboard
suspend fun <T> withBulkhead(config: BulkheadConfig = BulkheadConfig(), block: suspend () -> T): T

Executes an operation with bulkhead protection.

Link copied to clipboard
suspend fun <T> withBulkheadOrFallback(config: BulkheadConfig = BulkheadConfig(), fallback: suspend (Exception) -> T, block: suspend () -> T): T

Executes an operation with bulkhead protection and a fallback for rejection.

Link copied to clipboard
suspend fun <T> withTimeLimit(timeout: Duration, block: suspend () -> T): T

Extension function to add timeout to any suspend function.

Link copied to clipboard
suspend fun <T> withTimeLimitOrDefault(timeout: Duration, default: T, block: suspend () -> T): T

Extension function to add timeout with fallback to any suspend function.

Inherited functions

Link copied to clipboard
operator fun Policy.plus(other: Policy): Policy

Composes two policies so that this wraps other: (a + b).apply(block) runs as a.apply { b.apply(block) }.

Link copied to clipboard
fun <T> Flow<T>.retryWithBackoff(retries: Long = 3, base: Duration = 200.milliseconds, factor: Double = 2.0, jitterFactor: Double = 0.1, retryIf: (Throwable) -> Boolean = { it !is CancellationException }): Flow<T>

Retries collection of this Flow using exponential backoff with jitter, mirroring retryWithExponentialBackoff but for a whole flow instead of a single suspend call.

Link copied to clipboard
fun <T> Flow<T>.throughBulkhead(bulkhead: Bulkhead): Flow<T>

Protects collection of this Flow with a Bulkhead: the whole collection counts as a single call against the bulkhead's concurrency limit.

Link copied to clipboard
fun <T> Flow<T>.throughCircuitBreaker(circuitBreaker: CircuitBreaker): Flow<T>

Protects collection of this Flow with a CircuitBreaker: if the breaker is open, collecting fails fast with CircuitBreakerOpenException instead of starting the upstream flow.

Link copied to clipboard
fun <T> Flow<T>.throughPolicy(policy: Policy): Flow<T>

Applies an arbitrary Policy around collection of this Flow.

Link copied to clipboard
fun <T> Flow<T>.throughRateLimiter(rateLimiter: RateLimiter, permits: Int = 1): Flow<T>

Protects collection of this Flow with a RateLimiter: acquiring permits tokens gates when collection of the upstream flow is allowed to start.

Link copied to clipboard
fun <T> Flow<T>.throughTimeLimiter(timeLimiter: TimeLimiter, timeout: Duration? = null): Flow<T>

Bounds collection of this Flow with a TimeLimiter: if the whole collection doesn't complete within the timeout, it is cancelled.